package com.sgzn.sgpay.service.impl;

import com.sgzn.sgpay.enums.ReturnResultState;
import com.sgzn.sgpay.enums.SgsResponseCode;
import com.sgzn.sgpay.model.request.SgsAddDevicePresentLogRequest;
import com.sgzn.sgpay.model.request.SgsUserMerchantDiscountAddRequest;
import com.sgzn.sgpay.model.response.SgsResultResponse;
import com.sgzn.sgpay.persistence.dao.TDevicePresentLogMapper;
import com.sgzn.sgpay.persistence.domain.TDevicePresentLog;
import com.sgzn.sgpay.service.SgsDevicePresentLogService;
import com.sgzn.sgpay.service.support.SgsResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by linliangfang 13580393408
 * DATETIME:2018/6/10 11:09
 * Description:
 */
@Slf4j
@Service
public class SgsDevicePresentLogServiceImpl implements SgsDevicePresentLogService {

    @Resource
    private TDevicePresentLogMapper tDevicePresentLogMapper;




    /**
     * 新增设备礼品操作记录
     */
    @Override
    public SgsResultResponse<String> addDevicePresentLog(SgsAddDevicePresentLogRequest request){

        TDevicePresentLog tDevicePresentLog = new TDevicePresentLog();
        tDevicePresentLog.setDeviceId(request.getDeviceId());
        tDevicePresentLog.setMerchantId(request.getMerchantId());
        tDevicePresentLog.setShopId(request.getShopId());
        tDevicePresentLog.setOperType(request.getOperType());
        tDevicePresentLog.setOperNumber(Integer.parseInt(request.getOperNumber()));
        tDevicePresentLog.setPresentId(request.getPresentId());
        tDevicePresentLog.setCreatedAt(new Date());
        tDevicePresentLog.setUpdatedAt(new Date());

       int operNum =  tDevicePresentLogMapper.insertSelective( tDevicePresentLog );
       if(operNum != 1 ){
           return SgsResponseUtil.INSTANCE.fail(SgsResponseCode.C503.getResponseCode(),SgsResponseCode.C503.getResponseDesc());
       }
        return SgsResponseUtil.INSTANCE.success(ReturnResultState.SUCCESS.getCode());

    }



}
